<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQuery本地存储数据</title>
</head>
<body>
    <div>
        <p>本地存储，localStorage 是永久性存储，需要手动删除。可用于浏览器页面数据，当页面关闭后，重写打开页面还有数据。</p>
        <p>本地存储，存储的是字符串，在存储时需要将数据转换成字符串格式。</p>
        <p>存储语法：localStorage.setItem('key','value')</p>
        <p>获取语法：localStorage.getItem('key')</p>
        <p>删除语法：localStorage.removeItem('key')</p>
        <p>清空语法：localStorage.clear()</p>
    </div>
    <script>
        var arr = [{
            id:1,
            name:'张三',
            age:18,
            sex:'男'
        },{
            id:2,
            name:'李四',
            age:20,
            sex:'女'
        },{
            id:3,
            name:'王五',
            age:22,
            sex:'男'
        }]
        localStorage.setItem('todo',JSON.stringify(arr));
        var data = localStorage.getItem('todo');
        console.log(JSON.parse(data));
        var timer = setTimeout(() => {
            console.log('5s后删除本地存储 todo');
            setTimeout(() => {
                localStorage.removeItem('todo');
                console.log('本地存储已被删除')
            }, 5000);
        }, 10000);
    </script>
</body>
</html>